import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as session from 'express-session';
import type { NestExpressApplication } from '@nestjs/platform-express';
import { join } from 'path';
import { Response } from './common/response';
import { HttpError } from './common/error';
// import { LoginPipe } from './login/login/login.pipe';
import { ValidationPipe } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  const options = new DocumentBuilder()
    .setTitle('solar文档')
    .setDescription('api文档')
    .setVersion('1.0')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('/api-doc', app, document);
  app.useStaticAssets(join(__dirname, 'images'), {
    prefix: '/images',
  });
  app.use(
    session({
      secret: 'sun',
      rolling: true,
      cookie: { maxAge: 999999999 },
      name: 'ss.sid',
    }),
  );
  app.useGlobalFilters(new HttpError());
  app.useGlobalInterceptors(new Response());
  app.useGlobalPipes(new ValidationPipe());
  await app.listen(3000);
}
bootstrap();
